using System;
using System.Collections.Generic;
using System.Text;
using HTML;

using Microsoft.SharePoint;

namespace PointBridge.SPDX
{
    public class ContentTypesOptionSet : OptionsSet
    {
        #region Load/Save Methods
        public void LoadContentTypesFromListItem(SPListItem item)
        {
            try
            {
                string contentTypesXML = (string)item["ContentTypesXML"];
                LoadContentTypesFromXml(contentTypesXML);
            }
            catch(Exception)
            {
                Clear();
            }
        }
        public void SaveContentTypesToListItem(SPListItem item)
        {
            item["ContentTypesXML"] = SaveContentTypesToXml();
        }
        
        public string SaveContentTypesToXml()
        {
            return ToXMLString();
        }
        public void LoadContentTypesFromXml(string xml)
        {
            LAHTMLParser parser = new LAHTMLParser(xml);
            Clear();
            ParseXML(parser);
        }
        #endregion

        #region Methods
        public bool GetOptionValueNullReturnsFalse(string optionName)
        {
            OptionLine optionLine = FindByOptionNameNullsAllowed(optionName);

            if (optionLine == null) return false;
            else return optionLine.optionValue;
        }
        #endregion
    }
}
